/ leetcodesolve / Zigzag Conversion.py
swadhinbiswas update · 4/19/2024
3e2b57a
17 lines · 336 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class Solution:
    def convert(self, s: str, numRows: int) -> str:
      if numRows==1:
        return s
      listy=[""]*numRows
      index=0
      step=1
      for i in s:
        listy[index]+=i
        if index==0:
          step=1
        elif index==numRows-1:
          step=-1
        index+=step
      return "".join(listy)